<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Verifier extends CI_Controller {

	function __construct(){
    	parent::__construct();
        // load helper
        $this->load->helper('url');
        // load model
		$this->load->model('Verifier_model');
    }

	public function index()
	{
		show_404();		
	}

	public function login()
	{
		$uname = $this->input->post('username');
		$pw = $this->input->post('password');
		
		$response = $this->verifier_model->verify_login_return_info($uname,$pw);
		$this->output->set_content_type('application/json')->set_output(json_encode($response));
	}

	public function inquireInfo($id=-1)
	{
		$dataArray = array(
			'guardian'=> array(
				'guardian_id'=>'-1',
				'account_id'=>'-1',
				'last_name'=>'',
				'first_name'=>'',
				'middle_name'=>'',
				'address'=>'',
				'age'=>'-1',
				'birthday'=>'',
				'gender'=>'',
				'last_updated'=>'',
				'contact_number'=>''
			),
			'student'=>array(
				'student_id'=>'-1',
				'guardian_id'=>'-1',
				'last_name'=>'',
				'first_name'=>'',
				'middle_name'=>'',
				'address'=>'',
				'age'=>'-1',
				'birthday'=>'',
				'year_level'=>'',
				'school_year'=>'',
				'gender'=>'',
				'image_path'=>'',
				'last_updated'=>''
			)
		);

		if($id>-1){

			$student_response = $this->verifier_model->getStudent($id);
			$sID = -1;
			if(isset($student_response['0'])){
				$sID = $student_response['0']['guardian_id'];
			}
			
			if($sID>-1){
				$guardian_response = $this->verifier_model->getGuardian($sID);
			}
			// print_r("<pre>");
			// print_r($student_response['0']);
			// print_r("</pre>");

			// print_r("<pre>");
			// print_r($guardian_response['0']);
			// print_r("</pre>");

			
			if(isset($student_response['0'])){
				$dataArray['student'] = $student_response['0'];
			}
			if(isset($guardian_response['0'])){
				$dataArray['guardian'] = $guardian_response['0'];
			}
			
			
		}


		$this->output->set_content_type('application/json')->set_output(json_encode($dataArray));
	}
	
	
	
		
}
